﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportServiceRef;
    using WMS6.Web.UserControls;

    public class OwnerTransferRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15341;
        protected GridView gvOwnerTransferRpt;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlHead Head1;
        protected Label lblMsg;
        protected Label lblOwnerTransferRpt;
        protected Label lblTotalQty;
        protected Label lblTotalQtyText;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        private decimal TotalQty;
        protected UpdatePanel up1;

        private void BindData2gvOwnerTransferRptList(OwnerTransferRptQueryEntity ownerTransferRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(ownerTransferRptQueryEntity.CurrentPage);
            DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetOwnerTransferRptDataSet(ownerTransferRptQueryEntity);
            base.BindData2GridView(this.gvOwnerTransferRpt, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
            ownerTransferRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = ownerTransferRptQueryEntity.CurrentPage;
            ownerTransferRptQueryEntity.CurrentPage = "0";
            try
            {
                using (DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetOwnerTransferRptDataSet(ownerTransferRptQueryEntity))
                {
                    base.Export2Excel("OwnerTransferRpt.xls", "15341", this.gvOwnerTransferRpt, ds);
                }
            }
            finally
            {
                ownerTransferRptQueryEntity.IsGetAll = false;
                ownerTransferRptQueryEntity.CurrentPage = currentPageIndex;
                this.SetOwnerTransferRptQueryEntity(ownerTransferRptQueryEntity);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
            ownerTransferRptQueryEntity.CurrentPage = "0";
            this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
            ownerTransferRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
            ownerTransferRptQueryEntity.TransferID = "";
            ownerTransferRptQueryEntity.TransferDate = "";
            ownerTransferRptQueryEntity.FromOwnerID = "";
            ownerTransferRptQueryEntity.FromSkuID = "";
            ownerTransferRptQueryEntity.FromDescr = "";
            ownerTransferRptQueryEntity.ToSkuID = "";
            ownerTransferRptQueryEntity.ToOwnerID = "";
            ownerTransferRptQueryEntity.ToDescr = "";
            this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
            if (int.Parse(ownerTransferRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                ownerTransferRptQueryEntity.CurrentPage = (int.Parse(ownerTransferRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
            if (int.Parse(ownerTransferRptQueryEntity.CurrentPage) > 0)
            {
                ownerTransferRptQueryEntity.CurrentPage = (int.Parse(ownerTransferRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
            this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
        }

        private OwnerTransferRptQueryEntity GetOwnerTransferRptQueryEntity()
        {
            return (base.PageQueryEntitySession as OwnerTransferRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
                ownerTransferRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
            }
        }

        protected void gvOwnerTransferRpt_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15341", this.gvOwnerTransferRpt);
        }

        protected void gvOwnerTransferRpt_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblFROM_DESCR"));
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblTO_DESCR"));
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblREMARK"));
                }
                if (((Label) e.Row.FindControl("lblQTY")) != null)
                {
                    this.TotalQty += decimal.Parse((((Label) e.Row.FindControl("lblQTY")).Text != "") ? ((Label) e.Row.FindControl("lblQTY")).Text : "0");
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalQtyText.Text = base.GetPreferenceDigit(this.TotalQty);
            }
        }

        protected void gvOwnerTransferRpt_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = this.GetOwnerTransferRptQueryEntity();
                ownerTransferRptQueryEntity.SortField = e.SortExpression;
                if (ownerTransferRptQueryEntity.SortDirection == "ASC")
                {
                    ownerTransferRptQueryEntity.SortDirection = "DESC";
                }
                else if (ownerTransferRptQueryEntity.SortDirection == "DESC")
                {
                    ownerTransferRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            OwnerTransferRptQueryEntity ownerTransferRptQueryEntity = new OwnerTransferRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    ownerTransferRptQueryEntity.TransferID = this.PreviousPage.TransferID;
                    ownerTransferRptQueryEntity.TransferDate = this.PreviousPage.TransferDate;
                    ownerTransferRptQueryEntity.FromOwnerID = this.PreviousPage.FromOwnerID;
                    ownerTransferRptQueryEntity.FromSkuID = this.PreviousPage.FromSkuID;
                    ownerTransferRptQueryEntity.FromDescr = this.PreviousPage.FromDescr;
                    ownerTransferRptQueryEntity.ToSkuID = this.PreviousPage.ToSkuID;
                    ownerTransferRptQueryEntity.ToOwnerID = this.PreviousPage.ToOwnerID;
                    ownerTransferRptQueryEntity.ToDescr = this.PreviousPage.ToDescr;
                }
                else
                {
                    ownerTransferRptQueryEntity.TransferID = "";
                    ownerTransferRptQueryEntity.TransferDate = "";
                    ownerTransferRptQueryEntity.FromOwnerID = "";
                    ownerTransferRptQueryEntity.FromSkuID = "";
                    ownerTransferRptQueryEntity.FromDescr = "";
                    ownerTransferRptQueryEntity.ToSkuID = "";
                    ownerTransferRptQueryEntity.ToOwnerID = "";
                    ownerTransferRptQueryEntity.ToDescr = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            ownerTransferRptQueryEntity.IsGetAll = false;
            ownerTransferRptQueryEntity.CurrentPage = "0";
            ownerTransferRptQueryEntity.PageSize = this.gvOwnerTransferRpt.PageSize.ToString();
            ownerTransferRptQueryEntity.SortField = "TRANSFER_ID";
            ownerTransferRptQueryEntity.SortDirection = "DESC";
            this.PagerFooter.PageSize = this.gvOwnerTransferRpt.PageSize;
            this.SetOwnerTransferRptQueryEntity(ownerTransferRptQueryEntity);
            this.BindData2gvOwnerTransferRptList(ownerTransferRptQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvOwnerTransferRpt);
                this.LoadData();
            }
        }

        private void SetOwnerTransferRptQueryEntity(OwnerTransferRptQueryEntity ownerTransferRptQueryEntity)
        {
            base.PageQueryEntitySession = ownerTransferRptQueryEntity;
        }

        public OwnerTransferRptQuery PreviousPage
        {
            get
            {
                return (OwnerTransferRptQuery) base.PreviousPage;
            }
        }
    }
}

